package dyyx.cli;

import java.util.Map;

import dyyx.dto.SystemMetrics;
import dyyx.util.CommUtil;
import dyyx.util.ProcUtil;

public class XStatMain {
	
	
	
	

    public static void main(String[] args) throws Exception{   	
    	  
        int argnum = args.length;
        // 1 second  
        int fresh = 1;        
        if(argnum>0){
        	fresh = CommUtil.getInt(args[0]);
        }
        
        
        if(fresh==0){
        	SystemMetrics sm = ProcUtil.buildMetricData();
        	System.out.println(sm.time);
        	System.out.println(sm.timestamp);
        	System.out.println(sm.data);
        	System.out.println(sm.errorInfo);
 	
        	return;
        }
        
        if(fresh< 0 || fresh>60){
        	fresh = 1;
        }
        SystemMetrics current = null;
        
        
        SystemMetrics last = null;
        
        Map<String,String> map = null;
        
        while(true){
        	
        	current = ProcUtil.buildMetricData();
    		System.out.println(current.data);

        	
        	if(last!=null){
        		//long time = sm.timestamp - last.timestamp;
        		//map = ProcUtil.buildResult(last.data, sm.data, time);  
        		map = ProcUtil.buildResult(last, current);
        		System.out.println("    "+map);
        	}
        	
    		last = current;

        	CommUtil.doSleep(fresh * 1000L);
        	
        }
        
        
        
    }
}
